package service

import (
	"gorm.io/gorm"
	"week1/ordersrv/models"
)

func CreateOrderItem(tx *gorm.DB, item *models.OrderItems) (*models.OrderItems, error) {
	return item, tx.Create(item).Error
}
func CreateOrder(tx *gorm.DB, order *models.Order) (*models.Order, error) {
	return order, tx.Create(order).Error
}
func GetGoodsById(goodsId uint) (*models.Goods, error) {
	goods := new(models.Goods)
	return goods, models.DB.Where("id = ?", goodsId).First(goods).Error
}
func GetOrderByOrderSn(orderSn string) (*models.Order, error) {
	order := new(models.Order)
	return order, models.DB.Where("order_sn = ?", orderSn).First(order).Error
}

func GetGoodsDetailByOrderSn(orderSn string) ([]*models.OrderItems, error) {
	var order []*models.OrderItems
	return order, models.DB.Where("order_sn = ?", orderSn).Find(order).Error
}
